<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\admin\model;

use think\Model;


class Match extends Model
{



    CONST STATUS_INIT = 0;
    CONST STATUS_END = 1;
    CONST STATUS_CANCEL = 2;
    CONST NO_DELETED = 0;
    CONST IS_DELETED = 1;
    CONST SCORE = 'score_write';
    CONST SCORE_TITLE = '积分录入';
    CONST ROUND = 'round_start';
    CONST ROUND_TITLE = '轮次开始';
    CONST MATCH = 'match_end';
    CONST MATCH_TITLE = '赛事结束';

    CONST PURVIEW = [
        self::SCORE=>[
            'value'=>self::SCORE,
            'title'=>self::SCORE_TITLE
        ],

        self::ROUND=>[
            'value'=>self::ROUND,
            'title'=>self::ROUND_TITLE
        ],

        self::MATCH=>[
            'value'=>self::MATCH,
            'title'=>self::MATCH_TITLE
        ]
    ];
    // 表名
    protected $name = 'match';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'review_status_text',
        'type_text'
    ];
    

    
    public function getReviewStatusList()
    {
        return ['0' => __('Review_status 0'), '1' => __('Review_status 1'), '2' => __('Review_status 2')];
    }

    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1')];
    }


    public function getReviewStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['review_status']) ? $data['review_status'] : '');
        $list = $this->getReviewStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function merchant()
    {
        return $this->belongsTo('Merchant', 'merchant_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function store()
    {
        return $this->belongsTo('app\admin\model\merchant\Store', 's_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
